<template>
  <div style="width:100%;height:auto; margin:0 auto;">
    <el-form ref="ruleForm" :model="form" label-width="100px" :rules="rules">
      <el-form-item label="星级评价" prop="evaluationScore">
        <el-rate v-model="form.evaluationScore" show-text :allow-half="true" />
      </el-form-item>
      <el-form-item label="留言">
        <el-input v-model="form.message" type="textarea" />
      </el-form-item>
    </el-form>
    <div style="text-align:center;">
      <el-button type="primary" @click="save('ruleForm')">确定</el-button>
      <el-button type="danger" @click="closePage">取消</el-button>
    </div>
  </div>
</template>
<script>

import { saveData } from '@/api/publicFileEvaluate'
import { Message } from 'element-ui'

export default {
  inject: ['getList'],
  props: { // 第二种方式
    proid: {
      type: String,
      required: true
    }
  },
  data() {
    return {
      rules: {
        evaluationScore: [
          { required: true, message: '请选择星级评价', trigger: 'change', type: 'number', min: 0.5 }
        ]
      },
      form: {}
    }
  },
  methods: {
    save(ruleForm) { // 新增
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          const loading = this.$loading({
            lock: true,
            text: 'Loading',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
          })

          this.form.fileId = this.proid
          saveData(this.form).then(response => {
            Message({
              message: '评价成功',
              type: 'success',
              duration: 5 * 1000
            })

            this.$emit('update:visible', false)
            loading.close()
            this.getList()
          }).catch(response => {
            loading.close()
            this.getList()
          })
        } else {
          return false
        }
      })
    },
    closePage() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style scoped>

</style>
